load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"

begin

  plotname = "figure_hno3_scam5" 

  fna = "sgp_2010_cam5_apr.nc" 

  fla = addfile(fna,"r")

  hno3  = fla->hno3
  num_dust = fla->dust

  nt = dimsizes(hno3(:,0))

  nlev = dimsizes(hno3(0,:)) 

;;  hno3(:,:) = hno3(:,::-1) 
;;  num_dust(:,:) = num_dust(:,::-1) 

  print("HNO3 : "+hno3(100,:) ) 

  v1 = hno3
printVarSummary(v1) 

  v2 = v1 ;;duac
  v2 = (/ num_dust /) 

  vp = new((/2,nlev,nt/),"float")


  wks = gsn_open_wks("pdf",plotname) 
  gsn_define_colormap(wks,"BlueYellowRed") ; choose colormap

  
  res = True
  res@gsnDraw                = False
  res@gsnFrame               = False
 
  res@lbBoxMinorExtentF     = 0.15    
  res@lbOrientation         = "Vertical"
  res@lbLabelsOn            = True
  res@lbLabelFontHeightF    = 0.016
  res@lbLabelAutoStride     = True
  res@lbTitleFontHeightF    = 0.015
  res@tiXAxisFontHeightF    = 0.02
  res@tiXAxisString         = "Days" 
  res@tiYAxisFontHeightF    = 0.02
  res@tiYAxisString         = "Pressure (hPa)"
   
;  res@tmXBMinorOn           = False
  res@tmYLMinorOn           = False
  res@tmXTMinorOn           = False
  res@tmYRMinorOn           = False
  res@tmXTOn                = False
  ;;res@cnFillMode = "RasterFill" 
  
  ;;res@gsnRightString        = "" 
  ;;res@gsnLeftString         = "" 
  res@gsnStringFontHeightF  = 0.02
  res@gsnCenterStringFontHeightF  = 0.03
  
  res@cnFillOn             = True          ; turn on color
  res@gsnSpreadColors      = True     ; use full colormap
  res@cnLinesOn            = False    ; no contour lines
 
  res@gsnSpreadColors      = True          ; use full range of colormap
  
  ;;if (cmin.ne.cmax) then 
  ;;  res@cnLevelSelectionMode = "ManualLevels"
  ;;  res@cnLevelSpacingF      = cgap
  ;;  res@cnMinLevelValF       = cmin
  ;;  res@cnMaxLevelValF       = cmax
  ;;end if
  res@vpWidthF             = 0.8          ; change aspect ratio of plot
  res@vpHeightF            = 0.3
  ;;res@trYReverse           = True

;;  eta = (/ 0.9965, 0.988, 0.9765, 0.962, 0.944, 0.9215, 0.8945, 0.8605438, 0.8216314, \ 
;;    0.782719, 0.7438065, 0.6893758, 0.6218525, 0.5590411, 0.5006675, \ 
;;    0.4464713, 0.3962049, 0.3496331, 0.3065324, 0.2666907, 0.2299065, \ 
;;    0.1959889, 0.1647566, 0.136038, 0.1096703, 0.08549951, 0.06337969, \ 
;;    0.04317284, 0.02474841, 0.007982971 /) 
;;  eta = eta(::-1) 
 
;;  v1!0 = "time"
;;  v1!1 = "lev"
;;  v1&time = fspan(0,30,720) 
;;  v1&lev  = eta * 1000.
;;  v1&lev@units = "hPa"
;;  v1&lev@long_name = "Eta" ;;Pressure Levels"


  res@tmYRMode             = "Automatic"          ; turn off special labels on right axis

  plot = new(5,graphic)   


  res@cnLevelSelectionMode = "ExplicitLevels"    			; set explicit contour levels

  res@gsnLeftString = "a) HNO3 " 
  res@gsnRightString = "ppm" 
  res@cnLevels    = 1.e-3 * (/ 0.05, 0.1, 0.2, 0.5, 1., 2., 5. /) 
  plot(0) = gsn_csm_pres_hgt(wks,v1(lev|:,time|:),res)


  ;;delete(res@cnLevelSelectionMode) 
  delete(res@cnLevels) 
  res@gsnLeftString = "b) Dust number > 100nm"
  res@gsnRightString = "#/L"
  res@cnLevels    = 1.e3 * (/ 1.,2.,5.,10.,20.,50./) 
  plot(1) = gsn_csm_pres_hgt(wks,v2(lev|:,time|:),res)


;;............................................................................ 
;; draw panel with white space added
;;............................................................................ 
  resP                 = True
  resP@gsnPanelYWhiteSpacePercent = 5
  resP@gsnPanelXWhiteSpacePercent = 5
  gsn_panel(wks,plot,(/5,1/),resP)


end







